﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using YArchitech.ProgressBar;
using YArchitech.Revit;
using HYView;
using Transfer.Utils;

namespace ElectricMaterialStatistic
{
	internal class ElectricMaterialStatisticData
	{
        public ElectricMaterialStatisticData(Document doc, HYCodeBase.WinForm.WindowHandle handle)
		{
			this.m_doc = doc;
			this.m_lstSortLevel = FloorSelectManager.GetSortLevels(doc, double.MinValue, double.MaxValue);
			this.m_handle = handle;
		}

		public void GetStatisticElement(bool bLink, List<ViewPlan> lstViewPlan, List<FilterInfo> lstFilterInfo)
		{
			this.m_lstViewPlan = lstViewPlan;
			this.m_lstFilterInfo = lstFilterInfo;
			this.m_bLink = bLink;
			if (bLink)
			{
				this.m_lstLevelValue = this.GetLevelValue();
				this.m_view3D = this.GetView3D();
			}
			this.m_lstDicElement.Clear();
			this.ElementInDoc();
			if (this.m_bLink)
			{
				this.ElementInLinkDoc();
			}
		}

		public void GetStatisticElement(ViewPlan view, List<FilterInfo> lstFilterInfo, List<Element> lstElemSelArea)
		{
			this.m_view = view;
			this.m_lstFilterInfo = lstFilterInfo;
			this.m_lstElemInSelArea = lstElemSelArea;
			this.m_lstDicElement.Clear();
			this.ElementInSelAreaDoc();
		}

		private void ElementInDoc()
		{
			ProgressBarForm progressBarForm = new ProgressBarForm(this.m_lstFilterInfo.Count * this.m_lstViewPlan.Count, ProgressBarStyle.Blocks, true);
			progressBarForm.Text = "正在筛选构件。。。";
			progressBarForm.Show(this.m_handle);
			for (int i = 0; i < this.m_lstFilterInfo.Count; i++)
			{
				FilterInfo filterInfo = this.m_lstFilterInfo[i];
				Dictionary<ElementId, ElemParm> item = new Dictionary<ElementId, ElemParm>();
				foreach (Autodesk.Revit.DB.ViewPlan viewPlan in this.m_lstViewPlan)
				{
					ElementId elementId = viewPlan.GetUnderLayParameter().AsElementId();
					Transaction transaction = new Transaction(this.m_doc, "ChangeBaseLine");
					transaction.Start();
					viewPlan.GetUnderLayParameter().Set(ElementId.InvalidElementId);
					transaction.Commit();
					Categories categories = this.m_doc.Settings.Categories;
					try
					{
						BuiltInCategory builtInCategory = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), filterInfo.Category);
						string name = categories.get_Item(builtInCategory).Name;
						FilteredElementCollector collector = new FilteredElementCollector(this.m_doc, viewPlan.Id);
						if (filterInfo.Class == "FamilyInstance")
						{
							this.GetNonSystemFamilyInfo(filterInfo, collector, builtInCategory, name, ref item);
						}
						else
						{
							this.GetSystemFamilyInfo(filterInfo, collector, builtInCategory, viewPlan.GenLevel.Elevation, name, ref item);
						}
					}
					catch
					{
						continue;
					}
					transaction.Start();
					viewPlan.GetUnderLayParameter().Set(elementId);
					transaction.Commit();
					progressBarForm.RefreshProgressBar();
				}
				if (filterInfo.Category == "OST_CableTray" || filterInfo.Category == "OST_Conduit" || filterInfo.Category == "OST_CableTrayFitting")
				{
					this.SortDicData(ref item);
				}
				this.m_lstDicElement.Add(item);
				if (progressBarForm.m_stopTag)
				{
					break;
				}
			}
		}

		private void ElementInSelAreaDoc()
		{
			Categories categories = this.m_doc.Settings.Categories;
			int i = 0;
			while (i < this.m_lstFilterInfo.Count)
			{
				Dictionary<ElementId, ElemParm> dictionary = new Dictionary<ElementId, ElemParm>();
				try
				{
					FilterInfo filterInfo = this.m_lstFilterInfo[i];
					BuiltInCategory builtInCategory = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), this.m_lstFilterInfo[i].Category);
					string name = categories.get_Item(builtInCategory).Name;
					if (filterInfo.Class == "FamilyInstance")
					{
						this.GetNonSystemFamilyInfo(filterInfo, builtInCategory, name, ref dictionary);
					}
					else
					{
						this.GetSystemFamilyInfo(filterInfo, builtInCategory, name, ref dictionary);
					}
					if (dictionary.Count == this.m_lstElemInSelArea.Count)
					{
						break;
					}
				}
				catch
				{
					goto IL_B5;
				}
				goto IL_A9;
				IL_B5:
				i++;
				continue;
				IL_A9:
				this.m_lstDicElement.Add(dictionary);
				goto IL_B5;
			}
		}

		private void GetNonSystemFamilyInfo(FilterInfo filterInfo, FilteredElementCollector collector, BuiltInCategory biCategory, string strSysName, ref Dictionary<ElementId, ElemParm> dicSubItems)
		{
			foreach (Element element in collector.OfClass(typeof(FamilyInstance)).OfCategory(biCategory).ToElements())
			{
				if (this.m_bLink || !dicSubItems.ContainsKey(element.Id))
				{
					string name = (element as FamilyInstance).Symbol.Family.Name;
					List<List<string>> filterInfo2 = this.GetFilterInfo(element, filterInfo.LstLstFilter);
					string parmName = this.GetParmName(element, filterInfo.TbName);
					List<string> specification = this.GetSpecification(element, filterInfo.LstParm);
					ElemParm elemParm = new ElemParm(name, strSysName, parmName, specification, filterInfo2, filterInfo.Unit, 1.0);
					this.AddInDictionary(element.Id, elemParm, ref dicSubItems);
				}
			}
		}

		private void GetNonSystemFamilyInfo(FilterInfo filterInfo, BuiltInCategory biCategory, string strSysName, ref Dictionary<ElementId, ElemParm> dicSubItems)
		{
			foreach (Element element in this.m_lstElemInSelArea)
			{
				if (dicSubItems.ContainsKey(element.Id))
				{
					dicSubItems[element.Id].Amount += 1.0;
				}
                else if (element is FamilyInstance && element.Category.Id.IntegerValue == (int)biCategory)
				{
					string name = (element as FamilyInstance).Symbol.Family.Name;
					List<List<string>> filterInfo2 = this.GetFilterInfo(element, filterInfo.LstLstFilter);
					string parmName = this.GetParmName(element, filterInfo.TbName);
					List<string> specification = this.GetSpecification(element, filterInfo.LstParm);
					ElemParm value = new ElemParm(name, strSysName, parmName, specification, filterInfo2, filterInfo.Unit, 1.0);
					dicSubItems.Add(element.Id, value);
				}
			}
		}

		private void GetSystemFamilyInfo(FilterInfo filterInfo, FilteredElementCollector collector, BuiltInCategory biCategory, double dCurElevation, string strSysName, ref Dictionary<ElementId, ElemParm> dicSubItems)
		{
			foreach (Element element in collector.OfCategory(biCategory).ToElements())
			{
				if (this.m_bLink || !dicSubItems.ContainsKey(element.Id))
				{
					try
					{
						List<List<string>> filterInfo2 = this.GetFilterInfo(element, filterInfo.LstLstFilter);
						string parmName = this.GetParmName(element, filterInfo.TbName);
						List<string> specification = this.GetSpecification(element, filterInfo.LstParm);
						double dAmount = 0.0;
						this.GetElemAmount(element, filterInfo.Amount, filterInfo.Lg, dCurElevation, ref dAmount);
						ElemParm elemParm = new ElemParm("", strSysName, parmName, specification, filterInfo2, filterInfo.Unit, dAmount);
						this.AddInDictionary(element.Id, elemParm, ref dicSubItems);
					}
					catch
					{
					}
				}
			}
		}

		private void GetSystemFamilyInfo(FilterInfo filterInfo, BuiltInCategory biCategory, string strSysName, ref Dictionary<ElementId, ElemParm> dicSubItems)
		{
			foreach (Element element in this.m_lstElemInSelArea)
			{
				if (dicSubItems.ContainsKey(element.Id))
				{
					dicSubItems[element.Id].Amount += dicSubItems[element.Id].Amount;
				}
                else if (element.Category.Id.IntegerValue == (int)biCategory)
				{
					List<List<string>> filterInfo2 = this.GetFilterInfo(element, filterInfo.LstLstFilter);
					string parmName = this.GetParmName(element, filterInfo.TbName);
					List<string> specification = this.GetSpecification(element, filterInfo.LstParm);
					double dAmount = 0.0;
					this.GetElemAmount(element, filterInfo.Amount, filterInfo.Lg, this.m_view.GenLevel.Elevation, ref dAmount);
					ElemParm value = new ElemParm("", strSysName, parmName, specification, filterInfo2, filterInfo.Unit, dAmount);
					dicSubItems.Add(element.Id, value);
				}
			}
		}

		private List<List<string>> GetFilterInfo(Element elem, List<List<TypeBip>> lstLstFilter)
		{
			List<List<string>> list = new List<List<string>>();
			foreach (List<TypeBip> list2 in lstLstFilter)
			{
				List<string> list3 = new List<string>();
				foreach (TypeBip typeBip in list2)
				{
					string text = "";
					try
					{
						switch (typeBip.ValueType)
						{
						case 0u:
							text = typeBip.BuiltInParm;
							break;
						case 1u:
						{
							FamilyInstance familyInstance = elem as FamilyInstance;
							if (Convert.ToInt16(typeBip.BuiltInParm) == 0)
							{
								text = familyInstance.Symbol.Family.Name;
							}
							else
							{
								BuiltInParameter parameterId = (BuiltInParameter)Enum.Parse(typeof(BuiltInParameter), typeBip.BuiltInParm);
								text = familyInstance.Symbol.Family.GetParameter(parameterId).ToString();
							}
							break;
						}
						case 2u:
						{
							FamilyInstance familyInstance2 = elem as FamilyInstance;
							if (familyInstance2 == null)
							{
								text = elem.Name;
							}
							else if (Convert.ToInt16(typeBip.BuiltInParm) == 0)
							{
								text = familyInstance2.Symbol.Name;
							}
							else
							{
								BuiltInParameter parameterId2 = (BuiltInParameter)Enum.Parse(typeof(BuiltInParameter), typeBip.BuiltInParm);
								Parameter parameter = familyInstance2.Symbol.GetParameter(parameterId2);
                                if ((int)parameter.StorageType == 3)
								{
									text = parameter.AsString();
								}
								else
								{
									text = parameter.AsValueString();
								}
							}
							break;
						}
						case 3u:
						{
							BuiltInParameter parameterId3 = (BuiltInParameter)Enum.Parse(typeof(BuiltInParameter), typeBip.BuiltInParm);
							Parameter parameter2 = elem.GetParameter(parameterId3);
                            if ((int)parameter2.StorageType == 3)
							{
								text = parameter2.AsString();
							}
							else
							{
								text = parameter2.AsValueString();
							}
							break;
						}
						case 4u:
							if (typeBip.BuiltInParm.Contains('#'))
							{
								string[] array = typeBip.BuiltInParm.Split(new char[]
								{
									'#'
								});
								for (int i = 0; i < array.Length; i++)
								{
									if (!(array[i] == ""))
									{
										Parameter parameter3 = elem.GetParameter(array[i]);
                                        if ((int)parameter3.StorageType == 3)
										{
											text += parameter3.AsString();
											if (array[i] == "光源光通量")
											{
												text += " lm";
											}
										}
										else
										{
											text += elem.GetParameter(array[i]).AsValueString();
										}
										if (i != array.Length - 1)
										{
											text += ",";
										}
									}
								}
							}
							else
							{
								text = elem.GetParameter(typeBip.BuiltInParm).AsString();
							}
							break;
						case 5u:
							text = elem.GetParameter(typeBip.BuiltInParm).AsString();
							break;
						}
						list3.Add(text);
					}
					catch
					{
						list3.Add("");
					}
				}
				list.Add(list3);
			}
			return list;
		}

		private string GetParmName(Element elem, TypeBip tbName)
		{
			string result = "";
			switch (tbName.ValueType)
			{
			case 0u:
				result = tbName.BuiltInParm;
				break;
			case 1u:
			{
				FamilyInstance familyInstance = elem as FamilyInstance;
				if (Convert.ToInt16(tbName.BuiltInParm) == 0)
				{
					result = familyInstance.Symbol.Family.Name;
				}
				else
				{
					BuiltInParameter parameterId = (BuiltInParameter)Enum.Parse(typeof(BuiltInParameter), tbName.BuiltInParm);
					result = familyInstance.Symbol.Family.GetParameter(parameterId).ToString();
				}
				break;
			}
			case 2u:
			{
				FamilyInstance familyInstance2 = elem as FamilyInstance;
				if (familyInstance2 == null)
				{
					result = elem.Name;
				}
				else if (Convert.ToInt16(tbName.BuiltInParm) == 0)
				{
					result = familyInstance2.Symbol.Name;
				}
				else
				{
					BuiltInParameter parameterId2 = (BuiltInParameter)Enum.Parse(typeof(BuiltInParameter), tbName.BuiltInParm);
					result = familyInstance2.Symbol.GetParameter(parameterId2).ToString();
				}
				break;
			}
			case 3u:
			{
				BuiltInParameter parameterId3 = (BuiltInParameter)Enum.Parse(typeof(BuiltInParameter), tbName.BuiltInParm);
				result = elem.GetParameter(parameterId3).AsString();
				break;
			}
			case 4u:
				result = elem.GetParameter(tbName.BuiltInParm).AsString();
				break;
			}
			return result;
		}

		private List<string> GetSpecification(Element elem, List<TypeBip> lstParms)
		{
			List<string> list = new List<string>();
			foreach (TypeBip typeBip in lstParms)
			{
				switch (typeBip.ValueType)
				{
				case 0u:
					list.Add(typeBip.ParmName + typeBip.BuiltInParm);
					break;
				case 1u:
				{
					FamilyInstance familyInstance = elem as FamilyInstance;
					if (Convert.ToInt16(typeBip.BuiltInParm) == 0)
					{
						list.Add(typeBip.ParmName + familyInstance.Symbol.Family.Name);
					}
					else
					{
						BuiltInParameter parameterId = (BuiltInParameter)Enum.Parse(typeof(BuiltInParameter), typeBip.BuiltInParm);
						list.Add(typeBip.ParmName + familyInstance.Symbol.Family.GetParameter(parameterId).ToString());
					}
					break;
				}
				case 2u:
				{
					FamilyInstance familyInstance2 = elem as FamilyInstance;
					if (familyInstance2 == null)
					{
						list.Add(elem.Name);
					}
					else if (Convert.ToInt16(typeBip.BuiltInParm) == 0)
					{
						list.Add(typeBip.ParmName + familyInstance2.Symbol.Name);
					}
					else
					{
						BuiltInParameter parameterId2 = (BuiltInParameter)Enum.Parse(typeof(BuiltInParameter), typeBip.BuiltInParm);
						list.Add(typeBip.ParmName + familyInstance2.Symbol.GetParameter(parameterId2).ToString());
					}
					break;
				}
				case 3u:
				{
					BuiltInParameter parameterId3 = (BuiltInParameter)Enum.Parse(typeof(BuiltInParameter), typeBip.BuiltInParm);
					Parameter parameter = elem.GetParameter(parameterId3);
					list.Add(typeBip.ParmName + this.GetParameterValue(parameter));
					break;
				}
				case 4u:
				{
					Parameter parameter2 = elem.GetParameter(typeBip.BuiltInParm);
					list.Add(typeBip.ParmName + this.GetParameterValue(parameter2));
					break;
				}
				case 5u:
					list.Add(typeBip.ParmName + elem.GetParameter(typeBip.BuiltInParm).AsString());
					break;
				case 6u:
				{
					ParameterSet parameters = elem.Parameters;
					int num = 1;
					foreach (object obj in parameters)
					{
						Parameter parameter3 = (Parameter)obj;
                        BuiltInParameter builtInParameter = BuiltInParameter.INVALID;
						InternalDefinition internalDefinition = parameter3.Definition as InternalDefinition;
						if (internalDefinition != null)
						{
							builtInParameter = internalDefinition.BuiltInParameter;
						}
                        if ((int)parameter3.Definition.ParameterGroup == -1 && (int)builtInParameter == -1)
						{
							list.Add(string.Concat(new string[]
							{
								num.ToString(),
								".",
								parameter3.Definition.Name,
								":",
								parameter3.AsString()
							}));
							num++;
						}
					}
					break;
				}
				}
			}
			return list;
		}

		private void GetElemAmount(Element elem, uint nAmount, bool bLg, double dCurElevation, ref double value)
		{
			if (nAmount == 0u)
			{
				value = 1.0;
				return;
			}
			if (nAmount == 1u)
			{
				if (!bLg)
				{
					value = elem.GetParameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble();
				}
				else
				{
					LocationCurve locationCurve = elem.Location as LocationCurve;
					XYZ hyendPoint;
					XYZ hyendPoint2;
					if (locationCurve.Curve.GetEndPoint(0).Z - locationCurve.Curve.GetEndPoint(1).Z > 1E-09)
					{
						hyendPoint = locationCurve.Curve.GetEndPoint(1);
						hyendPoint2 = locationCurve.Curve.GetEndPoint(0);
					}
					else
					{
						hyendPoint = locationCurve.Curve.GetEndPoint(0);
						hyendPoint2 = locationCurve.Curve.GetEndPoint(1);
					}
					double num = (hyendPoint - hyendPoint2).AngleTo(XYZ.BasisZ);
					if (num < 0.0001 || Geometry.IsEqual(num, Math.PI))
					{
						double num2 = hyendPoint2.Z;
						for (int i = 0; i < this.m_lstSortLevel.Count; i++)
						{
							if (Math.Abs(this.m_lstSortLevel[i].Elevation - dCurElevation) < 1E-09 && i != 0)
							{
								num2 = this.m_lstSortLevel[i - 1].Elevation;
								break;
							}
						}
						if (Geometry.GreaterThan(hyendPoint2.Z, num2) && Geometry.LessThan(hyendPoint.Z, dCurElevation))
						{
							value = num2 - dCurElevation;
						}
						else if (Geometry.GreaterThan(hyendPoint2.Z, num2) && Geometry.GreaterThan(hyendPoint.Z, dCurElevation))
						{
							value = hyendPoint.Z - dCurElevation;
						}
						else if (Geometry.LessThan(hyendPoint2.Z, num2) && Geometry.LessThan(hyendPoint.Z, dCurElevation))
						{
							value = hyendPoint2.Z - dCurElevation;
						}
						else
						{
							value = elem.GetParameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble();
						}
					}
					else
					{
						value = elem.GetParameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble();
					}
				}
				value = UnitConvert.CovertFromAPI(0, value);
				return;
			}
		}

		private void ElementInLinkDoc()
		{
			if (this.m_view3D == null)
			{
				return;
			}
			List<RevitLinkInstance> allRevitLinkInstancesInDoc = this.GetAllRevitLinkInstancesInDoc();
			if (allRevitLinkInstancesInDoc.Count <= 0)
			{
				return;
			}
			for (int i = 0; i < this.m_lstFilterInfo.Count; i++)
			{
				Dictionary<ElementId, ElemParm> item = new Dictionary<ElementId, ElemParm>();
				foreach (double num in this.m_lstLevelValue)
				{
					foreach (RevitLinkInstance revitLinkInstance in allRevitLinkInstancesInDoc)
					{
						Document linkDocument = revitLinkInstance.GetLinkDocument();
						if (linkDocument != null)
						{
							BoundingBoxXYZ boundingBoxXYZ = revitLinkInstance.get_BoundingBox(this.m_view3D);
							if (boundingBoxXYZ != null && Geometry.IsEqual(boundingBoxXYZ.Min.Z, num))
							{
								Categories categories = linkDocument.Settings.Categories;
								try
								{
									FilterInfo filterInfo = this.m_lstFilterInfo[i];
									BuiltInCategory builtInCategory = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), filterInfo.Category);
									string name = categories.get_Item(builtInCategory).Name;
									FilteredElementCollector collector = new FilteredElementCollector(linkDocument);
									if (filterInfo.Class == "FamilyInstance")
									{
										this.GetNonSystemFamilyInfo(filterInfo, collector, builtInCategory, name, ref item);
									}
									else
									{
										this.GetSystemFamilyInfo(filterInfo, collector, builtInCategory, num, name, ref item);
									}
								}
								catch
								{
								}
							}
						}
					}
				}
				this.m_lstDicElement.Add(item);
			}
		}

		private void AddInDictionary(ElementId idElem, ElemParm elemParm, ref Dictionary<ElementId, ElemParm> dicElement)
		{
			if (!this.m_bLink)
			{
				dicElement.Add(idElem, elemParm);
				return;
			}
			if (dicElement.ContainsKey(idElem))
			{
				dicElement[idElem].Amount += elemParm.Amount;
				return;
			}
			dicElement.Add(idElem, elemParm);
		}

		private List<RevitLinkInstance> GetAllRevitLinkInstancesInDoc()
		{
			IEnumerable<ElementId> enumerable = new FilteredElementCollector(this.m_doc).OfClass(typeof(RevitLinkInstance)).ToElementIds();
			List<RevitLinkInstance> list = new List<RevitLinkInstance>();
			foreach (ElementId elementId in enumerable)
			{
				Element element = this.m_doc.GetElement(elementId);
				if (!(element.GetType() != typeof(RevitLinkInstance)))
				{
					RevitLinkInstance revitLinkInstance = element as RevitLinkInstance;
					if (revitLinkInstance != null)
					{
						list.Add(revitLinkInstance);
					}
				}
			}
			return list;
		}

		private List<double> GetLevelValue()
		{
			List<double> list = new List<double>();
			foreach (Autodesk.Revit.DB.ViewPlan viewPlan in this.m_lstViewPlan)
			{
				if (!list.Contains(viewPlan.GenLevel.Elevation))
				{
					list.Add(viewPlan.GenLevel.Elevation);
				}
			}
			list.Sort();
			return list;
		}

		private View3D GetView3D()
		{
			List<Element> list = new FilteredElementCollector(this.m_doc).OfClass(typeof(View3D)).OfCategory(BuiltInCategory.OST_Views).ToElements().ToList<Element>();
			View3D view3D = null;
			if (list.Count > 0)
			{
				foreach (Element element in list)
				{
					view3D = (element as Autodesk.Revit.DB.View3D);
					if (view3D.ViewName == "三维统计")
					{
						return view3D;
					}
				}
			}
			Transaction transaction = new Transaction(this.m_doc, "Create 3D view");
			transaction.Start();
			try
			{
				XYZ direction = new XYZ(-1.0, 1.0, -1.0);
				view3D = RevitVersionFuncs.NewView3D(this.m_doc, direction);
				view3D.ViewName = "三维统计";
				transaction.Commit();
			}
			catch
			{
				transaction.RollBack();
			}
			return view3D;
		}

		private string GetParameterValue(Parameter parm)
		{
			string result = "";
			if (parm == null)
			{
				return result;
			}
            switch ((int)parm.StorageType)
			{
			case 1:
				result = parm.AsInteger().ToString();
				break;
			case 2:
				result = parm.AsValueString();
				break;
			case 3:
				result = parm.AsString();
				break;
			case 4:
				result = parm.AsElementId().ToString();
				break;
			}
			return result;
		}

		private void SortDicData(ref Dictionary<ElementId, ElemParm> dicUnSort)
		{
			List<List<ElementId>> lstLstKeys = this.GroupingDic(dicUnSort);
			List<List<ElementId>> list = this.ListDataSort(lstLstKeys, dicUnSort);
			Dictionary<ElementId, ElemParm> dictionary = new Dictionary<ElementId, ElemParm>();
			foreach (List<ElementId> list2 in list)
			{
				foreach (ElementId key in list2)
				{
					dictionary.Add(key, dicUnSort[key]);
				}
			}
			dicUnSort.Clear();
			dicUnSort = dictionary;
		}

		private List<List<ElementId>> GroupingDic(Dictionary<ElementId, ElemParm> dicData)
		{
			List<List<ElementId>> list = new List<List<ElementId>>();
			int index = 0;
			List<ElementId> list2 = new List<ElementId>(dicData.Keys);
			for (int i = 0; i < list2.Count; i++)
			{
				List<ElementId> list3 = new List<ElementId>();
				string b = dicData[list2[i]].LstLstFilter[0][index];
				list3.Add(list2[i]);
				for (int j = i + 1; j < list2.Count; j++)
				{
					if (dicData[list2[j]].LstLstFilter[0][index] == b)
					{
						list3.Add(list2[j]);
						list2.Remove(list2[j]);
						j--;
					}
				}
				list.Add(list3);
			}
			return list;
		}

		private List<List<ElementId>> ListDataSort(List<List<ElementId>> lstLstKeys, Dictionary<ElementId, ElemParm> dicData)
		{
			List<List<ElementId>> list = new List<List<ElementId>>();
			if (lstLstKeys.Count <= 0)
			{
				return list;
			}
			int index = 1;
			foreach (List<ElementId> list2 in lstLstKeys)
			{
				List<ElementId> list3 = new List<ElementId>();
				List<double> lstValue = new List<double>();
				foreach (ElementId elementId in list2)
				{
					char[] charAryItem = dicData[elementId].LstLstFilter[0][index].ToCharArray();
					double headNumber = this.GetHeadNumber(charAryItem);
					int index2 = this.ListSort(lstValue, headNumber);
					list3.Insert(index2, elementId);
				}
				list.Add(list3);
			}
			return list;
		}

		private double GetHeadNumber(char[] charAryItem)
		{
			double result = -1.0;
			int i = 0;
			while (i < charAryItem.Length)
			{
				if (!char.IsNumber(charAryItem[i]))
				{
					char[] array = new char[i];
					Array.ConstrainedCopy(charAryItem, 0, array, 0, i);
					string text = new string(array);
					if (text == "")
					{
						result = double.MaxValue;
						break;
					}
					result = Convert.ToDouble(text);
					break;
				}
				else
				{
					i++;
				}
			}
			return result;
		}

		private int ListSort(List<double> lstValue, double dValue)
		{
			int num = lstValue.Count;
			for (int i = 0; i < lstValue.Count; i++)
			{
				if (Geometry.LessThan(dValue, lstValue[i]))
				{
					num = i;
					break;
				}
			}
			lstValue.Insert(num, dValue);
			return num;
		}

		public List<Dictionary<ElementId, ElemParm>> m_lstDicElement = new List<Dictionary<ElementId, ElemParm>>();

		private Document m_doc;

		private List<ViewPlan> m_lstViewPlan;

		private bool m_bLink;

		private List<FilterInfo> m_lstFilterInfo;

		private List<Level> m_lstSortLevel;

		private ViewPlan m_view;

		private List<Element> m_lstElemInSelArea;

		private List<double> m_lstLevelValue;

		private View3D m_view3D;

        private HYCodeBase.WinForm.WindowHandle m_handle;

		private const double _epsDouble = 1E-09;
	}
}
